package PTA;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class xt10_7_4 {
    public static void main(String[] args) {
        class NameComparator implements Comparator<PersonSortable2> {

            @Override
            public int compare(PersonSortable2 o1, PersonSortable2 o2) {
                return o1.getName().compareTo(o2.getName());
            }
        }
        class AgeComparator implements Comparator<PersonSortable2>{

            @Override
            public int compare(PersonSortable2 o1, PersonSortable2 o2) {
                return o1.getAge()-o2.getAge();
            }
        }
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        PersonSortable2 p[] =new PersonSortable2[n];
        for (int i=0;i<n;i++){
            String name=in.next();
            int age=in.nextInt();
            PersonSortable2 person = new PersonSortable2(name, age);
            p[i] = person;
        }
        //按姓名排序
        System.out.println("NameComparator:sort");
        Arrays.sort(p, new NameComparator()) ;
        for(PersonSortable2 i:p) {
            System.out.println(i);
        }
        //System.out.println(t);
        //按年龄排序
        System.out.println("AgeComparator:sort");
        Arrays.sort(p, new AgeComparator());
        for(PersonSortable2 i : p){
            System.out.println(i);
        }
        //输出接口类型
        System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
        System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
        in.close();

    }
}
class PersonSortable2{
    private String name;
    private int age;

    public PersonSortable2(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return name+"-"+age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
